let token =uni.getStorageSync('token')||''
//POST请求
function requestPOST(url, data) {
	let promise = new Promise(function(resolve, reject) {
		uni.showLoading({
			title: "加载中"
		})
		// console.log(token=="");
		uni.request({
			url,
			data,
			header: {
				"Content-Type": "application/x-www-form-urlencoded"
			},
			method: 'POST',
			success: (res) => {
				// console.log(res);
				uni.hideLoading()
				resolve(res.data)
			},
			fail: (res) => {
				// console.log(res);
				uni.hideLoading()
				reject(res)
			}
		})
	});
	return promise;
}
function requestPOST1(url, data) {
	let promise = new Promise(function(resolve, reject) {
		// console.log(token=="");
		uni.request({
			url,
			data,
			header: {
				"Content-Type": "application/x-www-form-urlencoded"
			},
			method: 'POST',
			success: (res) => {
				// console.log(res);
				resolve(res.data)
			},
			fail: (res) => {
				// console.log(res);
				reject(res)
			}
		})
	});
	return promise;
}


//GET请求
function requestGET(url, params) {
	let promise = new Promise(function(resolve, reject) {
		uni.request({
			url,
			data: params,
			method: 'GET',
			success: (res) => {
				resolve(res.data)
			},
			fail: (res) => {
				reject(res.data)
			}
		})
	});
	return promise;
}

//upload
function upload(url, params,folder) {
	let promise = new Promise(function(resolve, reject) {
		uni.showLoading({
			title: "加载中"
		})
		// 上传文件
		uni.uploadFile({
			url,
			filePath: params,
			name: 'file',
			formData: {
				folder: folder
			},
			success: (res) => {
				console.log(res);
				uni.hideLoading()
				resolve(JSON.parse(res.data))
			},
			fail: (res) => {
				uni.hideLoading()
				reject(res.data)
			}
		})
	});
	return promise
}

export default{
	requestPOST,
	requestPOST1,
	requestGET,
	upload
}
